package com.lovo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.bean.Tender;
import com.lovo.bean.Tenderinfo;

import com.lovo.dto.TenderDto;
import com.lovo.mapper.TenderMapper;
import com.lovo.service.ITenderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.service.ITenderinfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-09-17
 */
@Service
public class TenderServiceImpl extends ServiceImpl<TenderMapper, Tender> implements ITenderService {


    @Override
    public IPage<Tender> findNewTender(Integer pageNO) {

        QueryWrapper<Tender> qw = new QueryWrapper<>();
        qw.eq("t_status", "招标中");

        return baseMapper.selectPage(new Page<>(pageNO, 5), qw);

    }


    @RabbitListener(queues = "tenderQueue")
    public void sendTender(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag, TenderDto tenderDto) throws IOException {

        Tender tender = new Tender();
        BeanUtils.copyProperties(tenderDto, tender);
        System.err.println(tender);
        System.err.println(tenderDto);
        baseMapper.insert(tender);

        //手动确认
        channel.basicAck(tag, false);
    }


}
